﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;

namespace _180FrameWork.Common.WCFHelper
{
    public class BaseServiceRegister
    {
        /// <summary>
        /// dll运行路径
        /// </summary>
        private static string RuntimePath = LocationHelper.GetAppPath();

        public static Assembly[] GetDynamicAssemblyList(string CustomAssemblyPath)
        {
            //检查目录是否存在
            if (!Directory.Exists(CustomAssemblyPath))
            {
                Directory.CreateDirectory(CustomAssemblyPath);
            }
            IList<Assembly> list = new List<Assembly>();
            //将dll路径中的所有dll文件拷贝到dll运行路径
            foreach (var strfile in Directory.GetFiles(CustomAssemblyPath))
            {
                var file = new FileInfo(strfile);
                string strfilename = file.Name;
                file.CopyTo(RuntimePath + strfilename, true);
                //是否DLL
                if (Path.GetExtension(strfile).ToLower() == ".dll"
                    && strfile.ToLower().EndsWith("bll.dll"))
                {
                    list.Add(Assembly.LoadFrom(RuntimePath + strfilename));
                }
            }
            //循环所有dll运行路径中的dll文件
            return list.ToArray();
        }
    }
}
